#!/bin/bash

DATE=$(date +"%Y%m%d")
OUTPUT="sff_${DATE}_aarch64"
ZIP_FILE="$OUTPUT.zip"
RELEASE_DIR="../release"

echo "Building Android binary: $OUTPUT"

# 创建 release 目录
if [ ! -d "$RELEASE_DIR" ]; then
  mkdir -p $RELEASE_DIR
fi

# 设置编译参数
if ! CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o "$OUTPUT"; then
    echo "Build failed" >&2
    exit 1
fi

echo "Build succeeded: $OUTPUT"

# 压缩文件
if ! zip -q "$ZIP_FILE" "$OUTPUT"; then
    echo "Failed to create ZIP file." >&2
    exit 1
fi

echo "Created ZIP file: $ZIP_FILE"

# 移动 ZIP 文件
if ! mv -f "$ZIP_FILE" "$RELEASE_DIR/"; then
    echo "Failed to move ZIP file." >&2
    exit 1
fi

echo "Moved zip to $RELEASE_DIR/$ZIP_FILE"

# 可选：清理编译出的二进制文件
rm -f "$OUTPUT"
